﻿
/*******************************************************************************************
// ©2009 Microsoft Corporation.  This code is provided under the Microsoft Public License.
*******************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ClientBilling
{
    /// <summary>
    /// A record of a billed call between lawyer and client.
    /// </summary>
    public class BilledCallRecord
    {
        public string ConversationId { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public Client Client { get; set; }
        public List<CaseAllocation> CaseAllocations { get; set; }

        public BilledCallRecord(Client client, DateTime start)
        {
            if (client == null) throw new ArgumentNullException("Client cannot be null.");

            Client = client;
            Start = start;
        }

        /// <summary>
        /// The name of the client attached to this billed call.
        /// </summary>
        public string ClientName
        {
            get
            {
                if (Client == null) return string.Empty;
                else return Client.Name;
            }
        }

        /// <summary>
        /// The total length of the billed call as a TimeSpan.
        /// </summary>
        public TimeSpan CallDuration
        {
            get
            {
                if (EndIsBeforeStart())
                {
                    return new TimeSpan(0);
                }
                else
                {
                    return End.Subtract(Start);
                }
            }
        }

        private bool EndIsBeforeStart()
        {
            return End.CompareTo(Start) <= 0;
        }
    }
}
